/* eslint-disable */
// eslint-disable-next-line
import { MrxDbgUiPrPoint, MxFun, MxDbArrow } from 'mxdraw';

// 绘制箭头的函数
const drawArrow = async () => {
  const getPoint = new MrxDbgUiPrPoint();
  const arrow = new MxDbArrow(); // 创建箭头对象
  const mxDraw = MxFun.getCurrentDraw();

  // 设置箭头的线宽等属性
  arrow.setLineWidth(10);
  arrow.innerOffset = getScreenPixel(10);
  arrow.outerOffset = getScreenPixel(22);
  arrow.topOffset = getScreenPixel(36);

  // 设置图层为“Comment”
  arrow.layer = "Comment";

  // 获取用户点击的起点
  const startPoint = await getPoint.go();
  if (!startPoint) {
    throw new Error('获取起点失败');
  }
  arrow.startPoint = startPoint;

  // 设置动态绘制回调函数
  getPoint.setUserDraw((currentPoint, worldDraw) => {
    // 设置箭头的终点
    arrow.endPoint = currentPoint;
    // 动态绘制箭头
    worldDraw.drawCustomEntity(arrow);
  });

  // 获取用户点击的终点
  const endPoint = await getPoint.go();
  if (!endPoint) {
    throw new Error('获取终点失败');
  }
  arrow.endPoint = endPoint;

  // 将箭头添加到绘图中
  mxDraw.addMxEntity(arrow);
};

// 计算屏幕像素的实际世界坐标
function getScreenPixel(pixel, isFontSize = false) {
  let _pixel = MxFun.screenCoordLong2World(isFontSize ? pixel : pixel - pixel / 3);
  _pixel = MxFun.worldCoordLong2Doc(_pixel);
  return _pixel;
}

export { drawArrow };
